﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpTRI
{
    abstract class Bot : Character
    {
        protected float WalkRange { get; set; }
        static Random rnd = new Random(DateTime.Now.Millisecond);

        public Bot(float walkRange)
        {
            WalkRange = walkRange;
            Attributes.MoveSpeed = 1;
            Attributes.Damage = 1;

            Destination = GetRandomPoint();
            MoveToPoint(Destination);
            Attacked = false;

            Xors3D.xEntityColor(Mesh, 255, 128, 64);
            Xors3D.xEntityPickMode(Mesh, Xors3D.PICK_TRIMESH);
        }

        protected Vec3D GetRandomPoint()
        {
            float x = (float)rnd.NextDouble();
            float z = (float)rnd.NextDouble();
            return new Vec3D(WalkRange * x, 0, WalkRange * z);
        }

        public void Walk()
        {
            if (InPosition(Destination))
            {
                MoveToPoint(GetRandomPoint());
            }
        }

        public void FollowTo(Character target)
        {
            if (!InPosition(target.Position))
            {
                Destination = target.Position;
                Move();
            }
        }
    }
}
